package com.superman.supermarket.client.composite.commentlist;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.shared.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.utils.StringUtils;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.widget.star.CommentStarList;

/**
 * 评价
 * 
 * @author superman
 * @version 2018年8月18日下午5:19:17
 */
public class CommentListCellModule extends Composite implements IUIModule {

	interface CommentListCellModuleUiBinder extends UiBinder<Widget, CommentListCellModule> {
	}

	private static CommentListCellModuleUiBinder uiBinder = GWT.create(CommentListCellModuleUiBinder.class);

	@UiField
	Image headericon;
	@UiField
	HTML namehtml, timeandpropsnamehtml, detailhtml;
	@UiField
	CommentStarList star;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月18日 下午5:19:21
	 */
	public CommentListCellModule() {
		initWidget(uiBinder.createAndBindUi(this));
		star.addStar(5, false);
	}

	@Override
	public Map<String, Object> getData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setData(Map<String, Object> map) {
		if (map.get("ICON") == null)
			headericon.setUrl("images/my/header_default.png");
		else
			headericon.setUrl(String.valueOf(map.get("ICON")));

		namehtml.setText(StringUtils.hideStrByStar(String.valueOf(map.get("USER_NAME")), 1, 1));

		int score = (int) Double.parseDouble(String.valueOf(map.get("COMMENT_SCORE")));
		star.setValue(score);

		String timeStr = String.valueOf(map.get("COMMENT_TIME"));
		timeStr = com.google.gwt.i18n.client.DateTimeFormat.getFormat("yyyy-MM-dd")
				.format(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr));
		String prosNamesStr = String.valueOf(map.get("PROPS_NAME"));
		timeandpropsnamehtml.setHTML(timeStr + "&nbsp;&nbsp;" + prosNamesStr);

		detailhtml.setHTML(String.valueOf(map.get("CONTENT")));
	}

}
